#!/bin/bash
# scripts/publish.sh

set -e

VERSION=${1:-""}
if [ -z "$VERSION" ]; then
    echo "Usage: $0 <version>"
    echo "Example: $0 v1.0.1"
    exit 1
fi

echo "Publishing proto-contracts $VERSION..."

# 生成最新的proto文件
./scripts/gen-proto.sh
# 格式化代码
go fmt ./...

# 运行测试
go mod tidy

# 提交更改
git add .
git commit -m "Release $VERSION" || echo "No changes to commit"

# 创建标签
git tag $VERSION
git push origin master
git push origin $VERSION

echo "Published proto-contracts $VERSION successfully!"